package abel.wlmr.model.type;

import abel.wlmr.model.WlmrException;
import abel.wlmr.model.WlmrField;

public class EventCountField extends WlmrField {

    private short ec1;

    private short ec2;

    public EventCountField() {
        super(2);
    }

    @Override
    public int getValue() {
        return ec2 << 8 | ec1;
    }

    @Override
    public void parseValue(int v) throws WlmrException {
        ec1 = (short) (0xFF & v);
        ec2 = (short) ((0xFF00 & v) >> 8);
    }

    /**
     * @return the ec1
     */
    public short getEc1() {
        return ec1;
    }

    /**
     * @param v
     *            the ec1 to set
     */
    public void setEc1(short v) {
        if (v < 0 || v > 0xFF) {
            throw new IllegalArgumentException("ec1 should be [0,FFH]");
        }

        this.ec1 = v;
    }

    /**
     * @return the ec2
     */
    public short getEc2() {
        return ec2;
    }

    /**
     * @param v
     *            the ec2 to set
     */
    public void setEc2(short v) {
        if (v < 0 || v > 0xFF) {
            throw new IllegalArgumentException("ec2 should be [0,FFH]");
        }

        this.ec2 = v;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return String.format("{ec1:%s, ec2:%s}", ec1, ec2);
    }

}
